import axios from 'axios'
/* axios的封装增加复用性 */
// 获取用户列表
//put 参数是data,delete参数是params
//
export function getKeysList() {
          return  axios({
                method:'get',
                url:'/users',
            })
}
// 改变用户状态
export function changeUserStatus(params) {
            return axios({
                method:'put',
                url:`/users/${params.id}/state/${params.mg_state}`
            })
}
//添加用户
export function addUser(config) {
            return axios({
                method:'post',
                url:'/users',
                data:config
            })
}
//左侧菜单
export function getLeftMenus() {
            return axios({
                method:'get',
                url:'/menus'
            })
}
//编辑提交角色
export function editUser(params){
    return axios({
        method:'put',
        url:`users/${params.id}`,
        data:params
    })
}
//删除角色
export function deleteUser(id) {
            return axios({
                method:'delete',
                url:`/users/${id}`
            })
}
//得到权限列表,返回结果为列表方式
export function getRightsList() {
                return axios({
                    method:'get',
                    url:'/rights/list'
                })
}
//得到权限列表,返回结果为树状结构
export function getRightsListTree() {
    return axios({
        method:'get',
        url:'/rights/tree'
    })
}
//得到角色列表
export function getRolesList() {
            return axios({
                method:'get',
                url:'/roles'
            })
}
//编辑提交角色
export function editRole(params) {
            return axios({
                method:'put',
                url:`/roles/${params.roleId}`,
                data:params
            })
}
//添加角色
export function addRolePost(params) {
    return axios({
        method:'post',
        url:`/roles`,
        data:params
    })
}
//删除角色
export function deleteRoleDelete(id) {
                return axios({
                    method:'delete',
                    url:`/roles/${id}`
                })
}
//删除指定角色下的指定权限
export function deleRoleRightsDelete(roleId,rightId) {
                return axios({
                    method:'delete',
                    url:`/roles/${roleId}/rights/${rightId}`
                })
}
//分配权限
export function allotRoleRights(roleId,rights) {
                return axios({
                    method:'post',
                    url:`/roles/${roleId}/rights`,
                    data:{
                        rids:rights
                    }
                })
}
//分配用户角色
export function setUserRole(userId,roleId) {
        return axios({
            method:'put',
            url:`users/${userId}/role`,
            data:{
                    rid:roleId
            }
        })
}
//请求商品分类数据列表
export function getGoodsCate(params) {
            return axios({
                method:'get',
                url:'/categories',
                params
            })
}
//添加分类
export function addCategoryByAxios(data) {
                return axios({
                    method:'post',
                    url:'/categories',
                    data
                })
}
//编辑提交分类
export function editSubmitCategoryName(params) {
                return axios({
                    method:'put',
                    url:`/categories/${params.id}`,
                    data:{
                        cat_name:params.name
                    }
                })
}
//确认删除分类
export function confirmDeleteCategory(id) {
                return axios({
                    method:'delete',
                    url:`categories/${id}`
                })
}
//分类参数获取
export function getCategoryParmasByAxios(params) {
                       return axios({
                           method:'get',
                          url:`categories/${params.id}/attributes`,
                           params:{
                               sel:params.sel
                           }
                       })
}
//添加动态参数或者静态属性
export function addParamsByAxios(config){
    return axios({
        method:'post',
        url:`categories/${config.id}/attributes`,
        data:{
            attr_name:config.name,
            attr_sel:config.sel,
            attr_vals:config.val
        }
    })
}
//编辑提交参数
export function editParamsByAxios(config) {
    return axios({
        method:'put',
        url:`/categories/${config.cateId}/attributes/${config.attrId}`,
        data:{
            attr_name:config.name,
            attr_sel:config.sel,
            attr_vals:config.vals
        }
    })
}
//删除分类参数
export function deleteCategoryParamsByAxios(config) {
            return  axios({
                method:'DELETE',
                url:`categories/${config.cateId}/attributes/${config.attrId}`
            })
}
//----------------------------------------------------
//商品管理
//商品列表数据
export function getGoodsListByAxios(config) {
            return axios({
                method:'GET',
                url:'/goods',
                params:{
                   pagenum: config.pagenum,
                   pagesize: config.pagesize,
                   query:config.query
                }
            })
}
//根据id删除商品
export function deleteGoodsByAxios(id) {
            return axios({
                method:'DELETE',
                url:`goods/${id}`
            })
}       
//根据id查询商品    
export function searchByIdByAxios(id) {
        return axios({
            method:'GET',
            url:`goods/${id}`
        })
}
//编辑提交商品
export function editGoodsByAxios(config,id) {
        return axios({
            method:'put',
            url:`/goods/${id}`,
            data:config
        })
}
//添加商品
export function addGoodsByAxios(params) {
            return axios({
                method:'post',
                url:'/goods',
                data:params
            })
}
//----------------------------------------订单相关
// 获取订单列表
export function getOrderListByAxios(config) {
        return axios({
            method:'get',
            url:'/orders',
            params:{
                query:config.query,
                pagenum:config.pagenum,
                pagesize:config.pagesize
            }
        })
}